package com.lfk.justweengine.engine;


import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import ohos.media.image.PixelMap;
import ohos.media.image.common.PixelFormat;
import ohos.media.image.common.Size;
import org.junit.Assert;
import org.junit.Test;

public class GameTextureOhosTest {

    @Test
    public void testGetBitmap() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        GameTexture gameTexture = new GameTexture(context);
        PixelMap.InitializationOptions opts = new PixelMap.InitializationOptions();
        opts.pixelFormat = PixelFormat.ARGB_8888;
        opts.size = new Size(100, 500);
        gameTexture.setBitmap(PixelMap.create(opts));
        Assert.assertNotNull(gameTexture.getBitmap());
    }

    @Test
    public void testLoadFromAsset() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        GameTexture gameTexture = new GameTexture(context);
        Assert.assertTrue(gameTexture.loadFromAsset("resources/rawfile/graphic/icon.png"));
    }

    @Test
    public void testLoadFromAssetStripFrame() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        GameTexture gameTexture = new GameTexture(context);
        Assert.assertTrue(gameTexture.loadFromAssetStripFrame("resources/rawfile/graphic/icon.png", 0, 0, 100, 400));
    }

    @Test
    public void testLoadFromBigBitmap() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        GameTexture gameTexture = new GameTexture(context);
        PixelMap.InitializationOptions opts = new PixelMap.InitializationOptions();
        opts.pixelFormat = PixelFormat.ARGB_8888;
        opts.size = new Size(100, 500);
        PixelMap pixelMap = PixelMap.create(opts);
        gameTexture.setBitmap(pixelMap);
        PixelMap expPixelMap = gameTexture.loadFromBigBitmap(gameTexture, 0, 0, 100, 300);
        Assert.assertNotNull(expPixelMap);
    }

    @Test
    public void testGetFrameFromBitmap() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        GameTexture gameTexture = new GameTexture(context);
        PixelMap.InitializationOptions opts = new PixelMap.InitializationOptions();
        opts.pixelFormat = PixelFormat.ARGB_8888;
        opts.size = new Size(100, 500);
        PixelMap pixelMap = PixelMap.create(opts);
        gameTexture.setBitmap(pixelMap);
        GameTexture expGameTexture = gameTexture.getFrameFromBitmap(0,0,100,200);
        Assert.assertNotNull(expGameTexture.getBitmap());
    }
}